﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public class ThanhToanDAO
    {
        protected FDeal4Entities db;

        public ThanhToanDAO()
        {
            db = new FDeal4Entities();
        }

        public List<THANHTOAN> LietKe()
        {
            return db.THANHTOAN.ToList();
        }

        public THANHTOAN LayID(String id)
        {
            var tl = db.THANHTOAN.SingleOrDefault(t => t.IDHINHTHUC == id);
            return tl;
        }

        public THANHTOAN TimTen(String keyWord)
        {
            var tl = db.THANHTOAN.SingleOrDefault(t => t.TENHINHTHUC.Contains(keyWord));
            return tl;
        }

        public bool Them(THANHTOAN tl)
        {
            try
            {
                db.THANHTOAN.AddObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Xoa(THANHTOAN tl)
        {
            try
            {
                db.THANHTOAN.DeleteObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Sua(THANHTOAN tl)
        {
            try
            {
                THANHTOAN t1 = db.THANHTOAN.Single(t => t.IDHINHTHUC == tl.IDHINHTHUC);
                t1.IDHINHTHUC = tl.IDHINHTHUC;
                t1.TENHINHTHUC = tl.TENHINHTHUC;
                t1.PHITHANHTOAN = tl.PHITHANHTOAN;

                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
            	return false;
            }
        }
    }
}
